package com.example.classcommunity3.controller;

import com.example.classcommunity3.service.UserService;
import com.alibaba.fastjson.JSON;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping(params = "method=login")
    public String login(Long account, String psw, String character){
        System.out.println("LoginSystem");
        HashMap<String, Object> hashMap = userService.login(account, psw, character);
        String jsonResult = JSON.toJSONString(hashMap);

        System.out.println(jsonResult);
        return jsonResult;
    }

    @RequestMapping(params = "method=signIn")
    public boolean signIn(Long account, String psw, String character, String name){
        System.out.println(account + psw + character);

        return userService.signIn(account, psw, character, name);
    }

    @RequestMapping(params = "method=changePsw")
    public boolean changePsw(Long account, String pswOld, String pswNew){
        System.out.println(account + pswOld + pswNew);
        boolean b = userService.changePsw(account, pswOld, pswNew);

        return b;
    }

    @RequestMapping(params = "method=changeInfo")
    public boolean changeInfo(Long account, String character , String infoName){
        System.out.println(account + infoName);
        boolean b = userService.changeInfo(account, character, infoName);

        return b;
    }
}
